/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "post")
@NamedQueries({@NamedQuery(name = "Post.findById", query = "SELECT p FROM Post p WHERE p.id = :id"), @NamedQuery(name = "Post.findBySubject", query = "SELECT p FROM Post p WHERE p.subject = :subject"), @NamedQuery(name = "Post.findByPosted", query = "SELECT p FROM Post p WHERE p.posted = :posted"), @NamedQuery(name = "Post.findByOpened", query = "SELECT p FROM Post p WHERE p.opened = :opened")})
public class Post implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "subject")
    private String subject;
    @Lob
    @Column(name = "message")
    private String message;
    @Column(name = "posted", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date posted;
    @Column(name = "opened", nullable = false)
    private boolean opened;
    @JoinTable(name = "user_inbox", joinColumns = {@JoinColumn(name = "post", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "recipient", referencedColumnName = "email")})
    @ManyToMany
    private Collection<User> recipientCollection;
    @JoinTable(name = "user_wall", joinColumns = {@JoinColumn(name = "post", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "recipient", referencedColumnName = "email")})
    @ManyToMany
    private Collection<User> recipientCollection1;
    @JoinTable(name = "user_group_wall", joinColumns = {@JoinColumn(name = "post", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "recipient", referencedColumnName = "id")})
    @ManyToMany
    private Collection<UserGroup> recipientCollection2;
    @JoinColumn(name = "sender", referencedColumnName = "email")
    @ManyToOne
    private User sender;

    public Post() {
    }

    public Post(Integer id) {
        this.id = id;
    }

    public Post(Integer id, Date posted, boolean opened) {
        this.id = id;
        this.posted = posted;
        this.opened = opened;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Date getPosted() {
        return posted;
    }

    public void setPosted(Date posted) {
        this.posted = posted;
    }

    public boolean getOpened() {
        return opened;
    }

    public void setOpened(boolean opened) {
        this.opened = opened;
    }

    public Collection<User> getRecipientCollection() {
        return recipientCollection;
    }

    public void setRecipientCollection(Collection<User> recipientCollection) {
        this.recipientCollection = recipientCollection;
    }

    public Collection<User> getRecipientCollection1() {
        return recipientCollection1;
    }

    public void setRecipientCollection1(Collection<User> recipientCollection1) {
        this.recipientCollection1 = recipientCollection1;
    }

    public Collection<UserGroup> getRecipientCollection2() {
        return recipientCollection2;
    }

    public void setRecipientCollection2(Collection<UserGroup> recipientCollection2) {
        this.recipientCollection2 = recipientCollection2;
    }

    public User getSender() {
        return sender;
    }

    public void setSender(User sender) {
        this.sender = sender;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Post)) {
            return false;
        }
        Post other = (Post) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.Post[id=" + id + "]";
    }

}
